@Name("fluidOuncesConverter")
public class FluidOuncesConverter
{
public Double convertToMillilitres(Double ounces)
{
return ounces * 29.5735296;
}
}
With Arquillian Seam 2 extension you can easily test your applications created with Seam 2 framework against real containers!
Following features are supported:
Test enrichment for @In injection points from the Seam 2 Context.
Packaging support for adding the Seam 2 framework (so you don't need to specify it explictly in your @Deployment method).
You can turn off autopackaging feature in arquillian.xml. See "Additional configuration" section for details.
Let's consider following Seam 2 component
@Name("fluidOuncesConverter")
public class FluidOuncesConverter
{
public Double convertToMillilitres(Double ounces)
{
return ounces * 29.5735296;
}
}
In order to test it we can write standard Arquillian-powered test:
import static org.fest.assertions.Assertions.assertThat; // Fluent assertions used in the test
// ... Arquillian and Seam 2 relevant imports
@RunWith(Arquillian.class)
public class ComponentInjectionTestCase
{
@Deployment
public static Archive<?> createDeployment()
{
return ShrinkWrap.create(WebArchive.class, "test.war")
.addClass(FluidOuncesConverter.class)
.addPackages(true, "org.fest") // Needed to run in managed / remote container
.addAsResource(EmptyAsset.INSTANCE, "seam.properties")
.setWebXML("web.xml");
}
@In
FluidOuncesConverter fluidOuncesConverter;
@Test
public void shouldInjectSeamComponent() throws Exception
{
assertThat(fluidOuncesConverter).isNotNull();
}
@Test
public void shouldConvertFluidOuncesToMillilitres() throws Exception
{
// given
Double ouncesToConver = Double.valueOf(8.0d);
Double expectedMillilitres = Double.valueOf(236.5882368d);
// when
Double millilitres = fluidOuncesConverter.convertToMillilitres(ouncesToConver);
// then
assertThat(millilitres).isEqualTo(expectedMillilitres);
}
}
Under the hood Arquillian Seam 2 extension will enrich the test archive with all required dependencies needed for deploying Seam 2 application and deploy it to the container as web archive (WAR).
You can customize Arquillian Seam 2 extension configuration in arquillian.xml by adding following element:
<extension qualifier="seam2">
<!-- This way you can override Seam version
which you have defined in pom.xml -->
<property name="seamVersion">2.2.1.Final</property>
</extension>
List of all available properties
|
Property name |
Default value |
Description |
|
seamVersion |
2.2.2.Final |
Version of Seam 2 framework artifact used by autopackaging mechanism |
|
jbossElVersion |
1.0_02.CR5 |
Version of JBoss Expression Language extension artifact used by Seam 2 |
|
autoPackage |
true |
Turn on/off autopackaging feature. |
The only extra dependency needed is arquillian-seam2, as described in the snippet below.
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-seam2</artifactId>
<version>${version.arquillian.seam2}</version>
<scope>test</scope>
</dependency>
Take a look at the Getting started to see how you set up arquillian using maven.
Note: You might face problems obtaining some Seam 2 dependencies. You should add these repositories to fix the problem.